#cmake file for eRPC proxy
#author:guyadong
#created:2020/10/02
# MODULE方式查找依赖库,参见${PROJECT_SOURCE_DIR}/cmake/Modules/FindErpc.cmake
if(NOT TARGET erpc)
find_package(Erpc REQUIRED)
endif()
# 查找 thrift库
find_package(Thrift REQUIRED)
if(TARGET thrift_static)
	set(imported_thrift thrift_static)
elseif(TARGET thrift)
	set(imported_thrift thrift)
endif()
set (PROXY_NAME erpc_proxy)
# 定义所有的源文件列表
set(_stub_sources_dir ${CMAKE_CURRENT_LIST_DIR}/../client/stub)
aux_source_directory(${_stub_sources_dir} _STUB_SOURCES)
aux_source_directory(${CMAKE_CURRENT_LIST_DIR} _PROXY_SOURCES)
list(REMOVE_ITEM _PROXY_SOURCES ${CMAKE_CURRENT_LIST_DIR}/facelog_client.cpp)
add_executable(${PROXY_NAME} ${_STUB_SOURCES} ${_PROXY_SOURCES})

#########################
with_mt_if_msvc(${PROXY_NAME})
# MSVC Debug 编译时生成包含用于调试器的完整符号调试信息的 .obj 文件
# see also https://msdn.microsoft.com/zh-cn/library/958x11bc.aspx
# 添加NOMINMAX 避免与std::min(),std::max()函数宏定义min,max冲突
target_compile_options(${PROXY_NAME} PRIVATE $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Debug>>:/Z7> 
	$<$<CXX_COMPILER_ID:MSVC>:/wd4275 /wd4251> 
	$<$<CXX_COMPILER_ID:GNU>:-fpermissive -Wno-format-security>)
target_compile_definitions(${PROXY_NAME} 
			PRIVATE $<$<CXX_COMPILER_ID:MSVC>:NOMINMAX> 
	        PUBLIC _SL_USE_BYTE_STREAM 
					)
target_include_directories(${PROXY_NAME} PRIVATE ${_stub_sources_dir})
set_target_properties (${PROXY_NAME}  PROPERTIES 
	FOLDER "facelog"
	)

set(_link_libraries ${imported_thrift} common_source erpc)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
	list(APPEND _link_libraries -pthread)
endif()

target_link_libraries(${PROXY_NAME} ${_link_libraries}) 

################安装脚本#################
install(TARGETS ${PROXY_NAME}
  RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR}
  LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR}
  ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR}
  )

unset(_STUB_SOURCES)
unset(_PROXY_SOURCES)

